package cn.zhangyong.greendaolearn;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;

import java.util.List;

/**
 * description:用kotlin的时候有问题
 * autour: zhangyong
 * date: 2019/4/3 14:19
 * update: 2019/4/3
 * version:
 */
public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        final TextView tv = (TextView) findViewById(R.id.tv);
        findViewById(R.id.btn_add).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Shop shop = new Shop();
                shop.setName("三里屯" + System.currentTimeMillis());
                shop.setAddress("朝阳区");
                shop.setPrice("18.0");
                MyApp.getDaoSession().getShopDao().insert(shop);
            }
        });
        findViewById(R.id.btn_search).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                List<Shop> list = MyApp.getDaoSession().getShopDao().queryBuilder().where(ShopDao.Properties.Id.eq(1L)).list();
                if (list == null || list.size() == 0) {
                    tv.setText("空");
                } else {
                    tv.setText(list.get(0).toString());
                }
            }
        });
    }
}
